import { Form, Input, Radio, Modal } from "antd";
import React, { useState } from "react";
import FileUpload from "../FileUpload";
import FileUploadNew from '../FileUploadNew'
import UploadFileList from "./components/uploadFileField";

const formLayout = {
    labelCol: { span: 10 },
    wrapperCol: { span: 24 },
};

const BankRegist: React.FC<any> = ({
    visible,
    onCancel,
    onSubmit
}) => {
    const [form] = Form.useForm();
    const [confirmLoading, setConfirmLoading] = useState<any>(false);

    const getFileIds = (list: any) => {
        let arr: any = [];
        list.map((item: any) => {
            arr.push(item.fileId)
        })
        return arr.toString()
    }

    const handleSubmit = async () => {
        let params = {};
        let value = await form.validateFields();
        setConfirmLoading(true)
        let formValues = JSON.parse(JSON.stringify(value));
        Object.keys(formValues).map((item: any) => {
            if (item.indexOf('File') > -1) {
                params[item] = getFileIds(formValues[item])
            } else {
                params[item] = formValues[item]
            }
        })
        onSubmit(params, callback)
    }

    const callback = () => {
        setConfirmLoading(false)
    }

    return (
        <>
            <Modal
                title='金融机构入驻申请'
                visible={visible}
                onCancel={onCancel}
                onOk={handleSubmit}
                destroyOnClose={true}
                okText='提交'
                cancelText='取消'
                width='800px'
                confirmLoading={confirmLoading}
            >
                <Form
                    form={form}
                    {...formLayout}
                    initialValues={{
                        // applyName: formatDateIOS(new Date()) + '金融机构入驻申请'
                        type:1
                    }}
                    labelWrap={true}
                >
                    <Form.Item
                        label='类型'
                        name='type'
                        rules={[{ required: true, message: '请选择' }]}
                    >
                        <Radio.Group>
                            <Radio value={1}>银行</Radio>
                            <Radio value={2}>担保公司</Radio>
                            <Radio value={3}>保险公司</Radio>
                        </Radio.Group>
                    </Form.Item>
                    <Form.Item
                        name="applyName"
                        label="金融机构名称"
                        rules={[
                            { required: true, message: '请输入银行名称' },
                        ]}
                    >
                        <Input style={{ width: '260px' }} placeholder="请输入银行名称" />
                    </Form.Item>
                    <Form.Item
                        name="excelJson"
                        label="农民工工资业务经办分支机构说明（电子版）"
                        rules={[{ required: true, message: '请上传附件' }]}
                        extra='支持文件类型：.xlsx'
                    >
                        <UploadFileList />
                    </Form.Item>
                    <Form.Item
                        name="descriptionOfBranchAccessFile"
                        label="农民工工资业务经办分支机构说明（纸质盖章版）"
                        rules={[{ required: true, message: '请输入' }]}
                    >
                        <FileUpload
                            ossEnum="BANK"
                            multiple={true}
                            max={1}
                            hrefTaget={'downloadFile'}
                            actionUrl='/open/upload/resource'
                        />
                    </Form.Item>
                    <Form.Item
                        name="businessApplicationFile"
                        label="农民工工资保证金缴存业务申请书（纸质盖章版）"
                        rules={[{ required: true, message: '请输入' }]}
                    >
                        <FileUpload
                            ossEnum="BANK"
                            multiple={true}
                            max={6}
                            type="image/*,.pdf,.doc,.docx"
                            href={
                                'https://aurora-onlin-asserts.oss-cn-shanghai.aliyuncs.com/worker_supervision_oa/%E5%BC%80%E5%B1%95%E5%86%9C%E6%B0%91%E5%B7%A5%E5%B7%A5%E8%B5%84%E4%BF%9D%E8%AF%81%E9%87%91%E7%BC%B4%E5%AD%98%E4%B8%9A%E5%8A%A1%E7%94%B3%E8%AF%B7%E4%B9%A6.doc'
                            }
                            hrefText={'下载模版'}
                            hrefTaget={'downloadFile'}
                            actionUrl='/open/upload/resource'
                        />
                    </Form.Item>
                    <Form.Item
                        name="specialAccountBusinessApplicationFile"
                        label="农民工工资专用账户相关业务申请书（纸质盖章版）"
                        rules={[{ required: true, message: '请输入' }]}
                    >
                        <FileUploadNew
                            ossEnum="BANK"
                            multiple={true}
                            max={6}
                            type="image/*,.pdf,.doc,.docx"
                            href={
                                'https://aurora-onlin-asserts.oss-cn-shanghai.aliyuncs.com/worker_supervision_oa/%E5%BC%80%E5%B1%95%E5%86%9C%E6%B0%91%E5%B7%A5%E5%B7%A5%E8%B5%84%E4%B8%93%E7%94%A8%E8%B4%A6%E6%88%B7%E7%9B%B8%E5%85%B3%E4%B8%9A%E5%8A%A1%E7%94%B3%E8%AF%B7%E4%B9%A6.doc'
                            }
                            hrefText={'下载模版'}
                            hrefTaget={'downloadFile'}
                            actionUrl='/open/upload/resource'
                        />
                    </Form.Item>

                    <Form.Item
                        name="admissionCommitmentFile"
                        label="农民工保证金业务准入承诺书（纸质盖章版）"
                        rules={[{ required: true, message: '请输入' }]}
                    >
                        <FileUpload
                            ossEnum="BANK"
                            multiple={true}
                            max={6}
                            type="image/*,.pdf,.doc,.docx"
                            href={
                                'https://ossonline.goodrs.cn/worker_supervision_oa/%E5%86%9C%E6%B0%91%E5%B7%A5%E4%BF%9D%E8%AF%81%E9%87%91%E4%B8%9A%E5%8A%A1%E5%87%86%E5%85%A5%E6%89%BF%E8%AF%BA%E4%B9%A6.docx'
                            }
                            hrefText={'下载模版'}
                            hrefTaget={'downloadFile'}
                            actionUrl='/open/upload/resource'
                        />
                    </Form.Item>
                    <Form.Item
                        name="specialAccountAdmissionCommitmentFile"
                        label="农民工工资专用账户监管准入承诺书（纸质盖章版）"
                        rules={[{ required: true, message: '请输入' }]}
                    >
                        <FileUpload
                            ossEnum="BANK"
                            multiple={true}
                            max={6}
                            type="image/*,.pdf,.doc,.docx"
                            href={
                                'https://ossonline.goodrs.cn/worker_supervision_oa/%E5%86%9C%E6%B0%91%E5%B7%A5%E5%B7%A5%E8%B5%84%E4%B8%93%E7%94%A8%E8%B4%A6%E6%88%B7%E7%9B%91%E7%AE%A1%E5%87%86%E5%85%A5%E6%89%BF%E8%AF%BA%E4%B9%A6.docx'
                            }
                            hrefText={'下载模版'}
                            hrefTaget={'downloadFile'}
                            actionUrl='/open/upload/resource'
                        />
                    </Form.Item>
                    <Form.Item
                        name="name"
                        label="申请人"
                        rules={[
                            { required: true, message: '请输入' },

                        ]}
                    >
                        <Input style={{ width: '260px' }} placeholder="请输入" />
                    </Form.Item>
                    <Form.Item
                        name="phone"
                        label="申请人电话"
                        rules={[
                            { required: true, message: '请输入' },
                            {
                                pattern: /^1\d{10}$/,
                                message: '请输入正确手机号码'
                            }
                        ]}
                    >
                        <Input style={{ width: '260px' }} placeholder="请输入" />
                    </Form.Item>
                    <Form.Item
                        name="entrustFile"
                        label="申请人授权委托书"
                        rules={[{ required: true, message: '请输入' }]}
                    >
                        <FileUpload
                            ossEnum="BANK"
                            multiple={true}
                            max={6}
                            type="image/*,.pdf,.doc,.docx"
                            href={
                                'https://ossonline.goodrs.cn/worker_supervision_oa/%E9%93%B6%E8%A1%8C%E5%85%A5%E9%A9%BB%E7%94%B3%E8%AF%B7%E4%BA%BA%E6%8E%88%E6%9D%83%E5%A7%94%E6%89%98%E4%B9%A6.docx'
                            }
                            hrefText={'下载模版'}
                            hrefTaget={'downloadFile'}
                            actionUrl='/open/upload/resource'
                        />
                    </Form.Item>
                </Form>
            </Modal>
            <iframe style={{ display: 'none' }} name="downloadFile" />
        </>
    )
}

export default BankRegist